package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.entity.BsAllEmployeeVo;
import io.renren.modules.app.entity.BsAllMemberVo;
import io.renren.modules.app.entity.BsProtocolEntity;
import io.renren.modules.app.entity.QuarterProtocolDto;
import io.renren.modules.app.service.BsProtocolService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * 合同表
 *
 */
@RestController
@RequestMapping("tb_bs_protocol/bsprotocol")
public class BsProtocolController {
    @Autowired
    private BsProtocolService bsProtocolService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("tb_bs_protocol:bsprotocol:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsProtocolService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("tb_bs_protocol:bsprotocol:info")
    public R info(@PathVariable("id") Long id){
        BsProtocolEntity bsProtocol = bsProtocolService.getprotoById(id);
		//BsProtocolEntity bsProtocol = bsProtocolService.getById(id);

        return R.ok().put("bsProtocol", bsProtocol);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("tb_bs_protocol:bsprotocol:save")
    public R save(@RequestBody BsProtocolEntity bsProtocol, HttpServletRequest request){
        bsProtocolService.saveProtocol(bsProtocol,request);
		//bsProtocolService.save(bsProtocol);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("tb_bs_protocol:bsprotocol:update")
    public R update(@RequestBody BsProtocolEntity bsProtocol,HttpServletRequest request){
        bsProtocolService.updateProtocolById(bsProtocol,request);
		//bsProtocolService.updateById(bsProtocol);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("tb_bs_protocol:bsprotocol:delete")
    public R delete(@RequestBody Long[] ids){
		bsProtocolService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 合同数量季度统计接口
     */
    @RequestMapping("/quarterProtocol")
    public R quarterProtocol(){
        List<QuarterProtocolDto> quarterProtocolDto = bsProtocolService.quarterProtocol();
        return R.ok(quarterProtocolDto);
    }

    /**
     * 线索人数量季度统计接口
     */
    @RequestMapping("/quarterIntendCustomer")
    public R quarterIntendCustomer(){
        List<QuarterProtocolDto> quarterProtocolDto = bsProtocolService.quarterIntendCustomer();
        return R.ok(quarterProtocolDto) ;
    }

    /**
     * 统计季度销冠签订合同数量 季度统计接口
     */
    @RequestMapping("/quarterProtocolSignUser")
    public R quarterProtocolSignUser(){
        List<QuarterProtocolDto> quarterProtocolDto = bsProtocolService.quarterProtocolSignUser();
        return R.ok(quarterProtocolDto) ;
    }

    /**
     * 查询会员信息 下拉框准备
     * @return
     */
    @RequestMapping("/queryAllMember")
    public R queryAllMember(){
        List<BsAllMemberVo> list = bsProtocolService.queryAllMember();
        return R.ok(list);
    }

    /**
     * 查询员工信息 下拉框准备
     * @return
     */
    @RequestMapping("queryAllEmployee")
    public R queryAllEmployee(){
        List<BsAllEmployeeVo> list = bsProtocolService.queryAllEmployee();
        return R.ok(list);
    }


}
